WWL.toolbar = function ( name )
{
	var tbar = new WWL ( 'toolbar', name );

	tbar._items = [];
	tbar._buttons = {};

	tbar._event_names = [];	// Toolbar has no "direct" events

	tbar.mode = "H"; 	// "H"oriz or "V"ert

	// txt - Text of item
	// cback - callback function
	// style - Item style name
	// tooltip - Tooltip text (if not defined, the 'txt' attribute is used)
	// ref_name - reference name
	// disabled - T/F for disabled item
	// info - User defined Info
	tbar.add_item = function ( attrs ) // txt, cback, style, ref_name )
	{
		this._items.push ( attrs ); // { txt: txt, cback: cback, style: style, ref_name: ref_name } );
	};

	tbar.clear = function ()
	{
		tbar._items = [];
	};

	tbar.to_string = function ()
	{
		var t, l = this._items.length;
		var s = new String.buffer (), itm;
		var e, btn;
		var name, type;

		s.add (  '<div id="' + this.id + '"><table border="0" class="wwl_toolbar">' );

		if ( this.mode == 'H' ) s.add ( '<tr>' );

		for ( t = 0; t < l; t ++ )
		{
			if ( this.mode == 'V' ) s.add ( '<tr>' );
			s.add ( '<td>' );

			itm = this._items [ t ];

			type = itm.get ( "type", "button" );
			switch ( type )
			{
				case "split":
					if ( this.mode == 'H' )
						s.add ( '<span class="' + itm.get ( "style", "" ) + '">|</span>' );
					else
						s.add (  '<hr class="' + itm.get ( "style", "" ) + '" />' );
					break;

				case "newline":
					if ( this.mode == 'H' )
						s.add ( '</tr><tr>' );

				default:
					if ( itm [ 'cback' ] )
					{
						name =  this.id + "-btn" + t;
						btn = new WWL.button ( name );
						btn.label = itm.get ( 'txt', '' );
						btn.class_name = itm [ 'style' ];
						btn.tooltip = itm.get ( "tooltip", itm.get ( "txt", '' ) );
						btn.disable ( itm.get ( 'disabled' ) );
						btn.info = itm.get ( 'info' );

						s.add ( btn.to_string () );

						name = ( itm [ 'ref_name' ] ? itm [ 'ref_name' ] : name );
						tbar._buttons [ name ] = btn;

						btn.set_event ( 'click', itm [ 'cback' ] );
					} else
						s.add ( itm [ 'txt' ] );
					break;
			}

			s.add ( '</td>' );
			if ( this.mode == 'V' ) s.add ( '</tr>' );
		}

		s.add ( '</table></div>' );

		return s.get ();
	};

	tbar.get_item = function ( name )
	{
		return tbar._buttons [ name ];
	};

	tbar.disable_item = function ( name, disabled )
	{
		var b = tbar._buttons [ name ];
		if ( ! b ) return;

		b.disable ( disabled );
	};


	return tbar;
};

WWL.toolbar.get_instance = function ( instance_name )
{
	return WWL.get_instance ( "toolbar", instance_name );
};
